<?php
/**
 * @author Radovan Dvorsky
 * @version 20100514
 */
require_once ('library/My/Form/AjaxForm.php');

class Form_Block_SelectGroup extends My_Form_AjaxForm {
	
	private $_groups;
	
	public function init(){
		
		$cache = Zend_Registry::get('cache');
		$skRokMapper = new Db_Mapper_SkRok();
		$ID_sk = $skRokMapper->getActual();
		$cacheName = My_Support::getCacheName('HarmonogramController','fillGroup'.$ID_sk->getID_sk());
		
		if(!($this->_groups = $cache->load($cacheName))){
			$TTridyMapper = new Db_Mapper_TTridy();
			$this->_groups = $TTridyMapper->fetchGroupsForYear();			
			$cache->save($this->_groups,$cacheName);		
		}		
	}
	
	function __construct($url, $update, $format = 'html',$options = null) {
		parent::__construct($options);
		
		$this->setMethod('post');
		
		$this->setJqueryParams(array(
				'url' => $url,
				'update' => $update,
				'format' => $format	
			)			
		);
		
		$groups = new Zend_Form_Element_Select('ID_tr');
		$groups->setDecorators(array('ViewHelper'));	
		$groups->addMultiOption('-','Zvolte si triedu');
		
		foreach($this->_groups as $group){
			$groups->addMultiOption($group->ID_tr,$group->Zkratka);
		}
				
		$this->addAjaxableElements(array($groups));
		$this->setSender($groups,'onChange');
		
		$this->addElements(array($groups));
	}
}

?>